﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class paginas_Funcionarios : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var funcionario = ServiceGerenciador.Model.Funcionario.FindAll();

            if (funcionario.Length > 0)
                mvCrud.ActiveViewIndex = 0;//controle se existe registro e mostra a view
            else
                mvCrud.ActiveViewIndex = 1;

            gvCrud.DataSource = funcionario;
            gvCrud.DataBind();
        }
    }
    protected void btnNovo_Click(object sender, EventArgs e)
    {
        Response.Redirect("FuncionarioNovo.aspx");
    }
    protected void btnPesquisar_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtTermo.Text))
            return;

        var teste = ServiceGerenciador.Model.Funcionario.Pesquisa(txtTermo.Text).FirstOrDefault();

        if (teste == null)
        {
            lblPesquisa.Text = "Colaborador inexistente!";
        }
        else
        {
            lblPesquisa.Text = "";
            gvCrud.DataSource = ServiceGerenciador.Model.Funcionario.Pesquisa(txtTermo.Text);
        }
        gvCrud.DataBind();

    }
    protected void btnLimpar_Click(object sender, EventArgs e)
    {
        Response.Redirect("Funcionarios.aspx");
    }
}
